﻿using System;
using System.Collections.Generic;
using System.Text;

using GDCommon.Xml;
using GDCommon.Util;

namespace GDBLL.Map
{
    public class MapBLL
    {
        //TODO:Cache
        private static object lockHelper = new object();

        private static GDModel.Model.Map.Map m_map = null;

        private static string path = Common.GetMapPath("~/map/a001.map");
        private static string path2 = Common.GetMapPath("~/map/a002.map");

        static MapBLL()
        {
        }

        public static GDModel.Model.Map.Map LoadMap()
        {
            lock (lockHelper)
            {
                m_map = (GDModel.Model.Map.Map)XmlHelper.Load(typeof(GDModel.Model.Map.Map), path);
            }
            return m_map;
        }

        public static void SaveMap(GDModel.Model.Map.Map ml)
        {
            XmlHelper.Save(ml, path);
        }


        public static GDModel.Model.Map.Map LoadMap2()
        {
            lock (lockHelper)
            {
                m_map = (GDModel.Model.Map.Map)BinaryHelper.Load(typeof(GDModel.Model.Map.Map), path2);
            }
            return m_map;
        }

        public static void SaveMap2(GDModel.Model.Map.Map ml)
        {
            BinaryHelper.Save(ml, path2);
        }
    }
}
